package com.douwong.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.model.AppInfos;
import com.douwong.student.model.Holder;
import com.douwong.student.utils.UIUtils;

import java.util.ArrayList;


/**
 * @autor yichao
 * @time 2016/11/2510:54
 * @des 添加本地应用
 */
public class AddLocalAppAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<AppInfos> list;

    public AddLocalAppAdapter(Context context, ArrayList<AppInfos> list) {
        mContext = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list.size()!=0){
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder=null;
        if (convertView==null){
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.app_list_item, null);
            holder.title= (TextView) convertView.findViewById(R.id.app_name);
            holder.drawb = (ImageView) convertView.findViewById(R.id.app_drawable);
            convertView.setTag(holder);

        }{
            holder= (Holder) convertView.getTag();
        }
        if (list.size()>0){
            holder.title.setText(list.get(position).appName);
            holder.drawb.setImageDrawable(UIUtils.getAppIcon(list.get(position).packageName));
        }

        return convertView;
    }
}
